/**
 * @fileName: base.js
 * @author: coolboy11058@126.com
 * @time: 2017/5/8
 * @disc: axios 全局配置
 */
import Qs from 'qs';
import axios from 'axios';
import router from '@/router';
let instance = axios.create( {
  url: '',
  method: 'post',
  // baseURL: 'http://192.168.1.59:18081/agentfind_manager/',    //测试
  // baseURL: 'http://broker.haibeiclub.com:3501/agentfind_manager/',    //正式  汤姆环境
   baseURL: 'http://120.76.102.182:8891/agentfind_manager/',    //正式
  // baseURL:'',
  transformRequest: [ function ( data ) {
    let serizeData = Qs.stringify( data );
    return serizeData;
  } ],
  transformResponse: [ function ( data ) {
    let serizeData = Qs.parse( data );
    return serizeData;
  } ],
  data: {},
  withCredentials: true,
  // crossDomain:true,
  responseType: 'json',
  timeout: 100000
} );
/**
 * 添加Cookie请求头信息
 */

instance.interceptors.request.use( config => {
  // config.withCredentials = true;
  return config;
}, e => {
  return Promise.reject( e );
} );
/**
 * 添加拦截器响应
 */
instance.interceptors.response.use( res => {
  return res;
}, e => {
  if ( e.response ) {
    switch ( e.response.status ) {
      case 401:
      case 403:
        router.push( { name: 'login' } );
        break;
    }
  }
  return Promise.reject( e );
} );
export default instance;
